package com.anjbo.service.house.impl;

import com.anjbo.bean.house.HouseRpValueDto;
import com.anjbo.bean.property.TZCPropertyDto;
import com.anjbo.dao.app.house.HouseMapper;

import com.anjbo.dao.mort.house.HouseDetailMapper;
import com.anjbo.dao.mort.house.HouseRentPriceMapper;
import com.anjbo.service.house.HouseService;
import com.anjbo.service.property.PropertyAVGService;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;


import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by zsy on 2017/3/3.
 */

@Service
public class HouseServiceImpl implements HouseService {

    @Autowired(required=true)
    private HouseMapper houseMapper;
    @Autowired(required=true)
    private HouseRentPriceMapper houseRentPriceMapper;

    @Autowired
    private HouseDetailMapper houseDetailMapper;



    /**
     * zl接口为房产详情统计表做服务
     */
    @Autowired
    private PropertyAVGService propertyAVGService;

    @Override
    public int insertHouse(Map<String, Object> params,Double unitPrice) {
        this.computePrice(params,unitPrice);//调用计算方法计算房产所需价格

        return houseMapper.insertHouse(params);
    }

    @Override
    public int updateHouse(Map<String, Object> params) {
        return houseMapper.updateHouse(params);
    }



    @Override
    public Map<String, Object> selectHouseDetail(Map<String, Object> params) {
        return houseMapper.selectHouseDetail(params);
    }

    @Override
    public List<Map<String, Object>> selectHouseList(Map<String, Object> params) {
        return houseMapper.selectHouseList(params);
    }

    /*@Override
    public Map<String, Object> selectHouseAsset(Map<String, Object> params) {
        return houseMapper.selectHouseAsset(params);
    }*/



    /**
     * 获取房产管理页面数组
     * @param params
     * @return 资产总值，总增值，房产列表数据
     */

    @Override
    public Map<String, Object> assetManagement(Map<String, Object> params) {
        Map<String,Object> map =new HashMap<String,Object>();
        int hasHouse=0;
        try {
            List<Map<String,Object>> list=this.selectHouseList(params);
            //Map<String,Object> mapAsset=this.selectHouseAsset(params);

            int sumPrice=0;
            int appreciation=0;
            int loanBalance=0;

            for(int i=0;i<list.size();i++){
                Map<String,Object> mapTemp=list.get(i);
                sumPrice+=(int)(MapUtils.getDouble(mapTemp,"sumPrice")/10000);
                appreciation+=(int)(MapUtils.getDouble(mapTemp,"appreciation")/10000);
                loanBalance+=(int)(MapUtils.getDouble(mapTemp,"loanBalance")/10000);
            }
            hasHouse=houseMapper.selectHasHouseList(params);
            map.put("sumPrice",sumPrice-loanBalance);
            map.put("hasHouse",hasHouse);
            map.put("appreciation",appreciation);
            map.put("houseList",list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    /**
     * 查询房产单价信息
     * @param params
     * @return
     */
    @Override
    public List<Map<String,Object>> getHousePrice(Map<String, Object> params) {
        return houseMapper.getHousePrice(params);
    }
    /**
     * 根据参数处理价格方法（单价，总价，增值，租金，可贷金额）
     * @param params
     * @return map (返回所有计算后价格)
     */
    @Override
    public Map<String, Object> computePrice(Map<String, Object> params,Double unitPrice) {
        double boughtPrice=0.0;//购买价格
        double loanBalance=0.0;//可贷金额
        double appreciation=0.0;//增值
        double sumPrice=0.0;//总价
        double loanablePrice=0.0;//可贷金额
        boughtPrice=10000 * MapUtils.getDoubleValue(params,"boughtPrice",0.0);//获取购买价格参数*10000
        loanBalance=10000 * MapUtils.getDoubleValue(params,"loanBalance",0.0);//获取貸款余额参数*10000


        Double acreage=MapUtils.getDoubleValue(params,"acreage",0.0);//获取面积
        //rp值
        Double rp=0.0;
        //均单价
        Double avgPrice=0.0;
        //物业均单价
        Double loatSumPrice=0.0;

        try {
            rp=this.getRpValue(params);
            Map<String,Object> priceAvgMap=this.getAvgValue(params);
            avgPrice=MapUtils.getDoubleValue(priceAvgMap,"avgPrice",0.0);//匹配纬度获得单价
            loatSumPrice=MapUtils.getDoubleValue(priceAvgMap,"loatSumPrice",0.0);//匹配失败返回物业均价
            if(avgPrice!=null||unitPrice!=null){
                if(avgPrice!=null&&avgPrice>0){
                    //均单价和询价接口同在取两者之和参与计算
                    if(unitPrice!=null && unitPrice>0){
                        Double loadPrice=avgPrice*0.8;//保留平均价格80%
                        Double rpPrice=avgPrice*0.2*rp;//取均价20%参与计算RP值
                        avgPrice=rpPrice+loadPrice+unitPrice;
                        avgPrice=avgPrice/2;
                    }else{
                        //询价接口返回单价为空或小于0时只取均单价参与计算
                        Double loadPrice=avgPrice-avgPrice*0.2;
                        Double rpPrice=avgPrice*0.2*rp;
                        avgPrice=rpPrice+loadPrice;
                    }
                    sumPrice=avgPrice * acreage;//总价
                    appreciation=sumPrice-boughtPrice;
                    loanablePrice= sumPrice * 0.7;
                }else {
                    //均单价价为空或小于0时取询价接口单价参与计算
                    if(unitPrice!=null && unitPrice>0){
                        Double loadPrice=unitPrice-unitPrice*0.2;
                        Double rpPrice=unitPrice*0.2*rp;
                        avgPrice=rpPrice+loadPrice;
                    }else{
                        //询价接口，均单价皆为空时返回物业均价
                        Double loadPrice=loatSumPrice-loatSumPrice*0.2;
                        Double rpPrice=loatSumPrice*0.2*rp;
                        avgPrice=rpPrice+loadPrice;
                    }
                    sumPrice=avgPrice * acreage;//总价
                    appreciation=sumPrice-boughtPrice;
                    loanablePrice= sumPrice * 0.7;
                }

            }

        } catch (Exception e) {
            avgPrice=0.0;
            e.printStackTrace();
        }


        //租金
        Double rentalPrice=0.0;
        try {
            rentalPrice=this.getRentPrice(params);
            if(rentalPrice==null){
                rentalPrice=0.0;
            }
        } catch (Exception e) {
            rentalPrice=0.0;
            e.printStackTrace();
        }
        if(Double.isNaN(rentalPrice))
        {
            rentalPrice=0.0;
        }
        if(Double.isNaN(avgPrice)){
            sumPrice=0.0;//总价
            appreciation=0.0;
            loanablePrice=0.0;
        }

        params.put("sumPrice",new BigDecimal(sumPrice).setScale(2,BigDecimal.ROUND_HALF_UP));//现总价
        params.put("price",new BigDecimal(avgPrice).setScale(2,BigDecimal.ROUND_HALF_UP));//现单价
        params.put("boughtPrice",new BigDecimal(boughtPrice).setScale(2,BigDecimal.ROUND_HALF_UP));//购买价格
        params.put("appreciation",new BigDecimal(appreciation).setScale(2,BigDecimal.ROUND_HALF_UP));//现增值
        params.put("loanBalance",new BigDecimal(loanBalance).setScale(2,BigDecimal.ROUND_HALF_UP));//贷款余额
        params.put("loanablePrice",new BigDecimal(loanablePrice).setScale(2,BigDecimal.ROUND_HALF_UP));//可贷金额
        params.put("rentalPrice",new BigDecimal(rentalPrice).setScale(2,BigDecimal.ROUND_HALF_UP));//租金
        params.put("state",0);//房产状态（0显示，1隐藏）定时任务更新删除状态为1的信息
        return params;
    }

    /**
     * 获取租金
     * @param params
     * @return
     */
    public double getRentPrice(Map<String,Object> params){
        List<Map<String,Object>> rentPriceListMap=houseRentPriceMapper.getRentalPrice(params);//获取租金
        //获取输入面积
        Double userArea=MapUtils.getDouble(params,"acreage");
        Double rentPrice=0.0;
        int tempSize=0;
            if(userArea>180){
                //用户匹配输入范围180-9999
                for(int i=0;i<rentPriceListMap.size();i++){
                    Map<String,Object> map=rentPriceListMap.get(i);
                    Double area=MapUtils.getDouble(map,"area");
                    if(area>180){
                        rentPrice+=MapUtils.getDouble(map,"rentalPrice");
                        tempSize++;
                    }

                }


            }else if(userArea>140){
                //用户匹配输入范围140-180
                for(int i=0;i<rentPriceListMap.size();i++){
                    Map<String,Object> map=rentPriceListMap.get(i);
                    Double area=MapUtils.getDouble(map,"area");
                    if(area>140 && area<=180){
                        rentPrice+=MapUtils.getDouble(map,"rentalPrice");
                        tempSize++;

                    }

                }

            }
            else if(userArea>120){
                //用户匹配输入范围120-140
                for(int i=0;i<rentPriceListMap.size();i++){
                    Map<String,Object> map=rentPriceListMap.get(i);
                    Double area=MapUtils.getDouble(map,"area");
                    if(area>120 && area<=140){
                        rentPrice+=MapUtils.getDouble(map,"rentalPrice");
                        tempSize++;

                    }

                }

            }else if(userArea>110){
                //用户匹配输入范围110-120
                for(int i=0;i<rentPriceListMap.size();i++){
                    Map<String,Object> map=rentPriceListMap.get(i);
                    Double area=MapUtils.getDouble(map,"area");
                    if(area>110 && area<=120){
                        rentPrice+=MapUtils.getDouble(map,"rentalPrice");
                        tempSize++;

                    }
                }

            }else if(userArea>90){
                //用户匹配输入范围90-110
                for(int i=0;i<rentPriceListMap.size();i++){
                    Map<String,Object> map=rentPriceListMap.get(i);
                    Double area=MapUtils.getDouble(map,"area");
                    if(area>90 && area<=110){
                        rentPrice+=MapUtils.getDouble(map,"rentalPrice");
                        tempSize++;

                    }
                }

            }else if(userArea>70){
                //用户匹配输入范围70-90
                for(int i=0;i<rentPriceListMap.size();i++){
                    Map<String,Object> map=rentPriceListMap.get(i);
                    Double area=MapUtils.getDouble(map,"area");
                    if(area>70 && area<=90){
                        rentPrice+=MapUtils.getDouble(map,"rentalPrice");
                        tempSize++;
                    }

                }

            }else if(userArea>=1){
                //用户匹配输入范围0-70
                for(int i=0;i<rentPriceListMap.size();i++){
                    Map<String,Object> map=rentPriceListMap.get(i);
                    Double area=MapUtils.getDouble(map,"area");
                    if(area<=70){
                        rentPrice+=MapUtils.getDouble(map,"rentalPrice");
                        tempSize++;
                    }

                }

            }

        if(rentPrice>0)
        {
            rentPrice=rentPrice/tempSize;
            return rentPrice*userArea;
        }else{
            for(int i=0;i<rentPriceListMap.size();i++){

                Map<String,Object> mapTemp=rentPriceListMap.get(i);
                rentPrice+=MapUtils.getDouble(mapTemp,"rentalPrice");
                tempSize++;

            }
            rentPrice=rentPrice/tempSize;
            return rentPrice*userArea;
        }
    }

    /**
     * 获取单价（根据纬度来获取单价）
     * @param params
     * @return
     */
    private Map<String,Object> getAvgValue(Map<String,Object> params){
        List<Map<String,Object>> list=new ArrayList();
        list=this.getHousePrice(params);//获取价格结果集
        Double loatSumPrice=0.0;//所有记录总值
        Double avgPrice=0.0;//均单价
        Double area=MapUtils.getDouble(params,"acreage");//获取面积
        String AreaKey=this.retrunAvgArea(area);//获取面积key
        String bulidName=MapUtils.getString(params,"buildingName");//楼栋
        for(int i=0;i<list.size();i++){
            Map<String,Object> map=list.get(i);
            //判断楼栋相同，面积在范围内返回均价
            String buildingName=MapUtils.getString(map,"buildingName");
            String AreaMapString=MapUtils.getString(map,"area");
            //等值匹配，匹配面积范围，匹配楼栋名称
            if(StringUtils.equals(AreaKey,AreaMapString) && StringUtils.equals(bulidName,buildingName)){
                avgPrice=MapUtils.getDouble(map,"estatePrice");
            }
            //统计总价
            loatSumPrice+=MapUtils.getDouble(map,"estatePrice");
        }
        Map<String,Object> priceMap=new HashedMap();
        if(avgPrice!=null && avgPrice>0){
            priceMap.put("avgPrice",avgPrice);
        }else if(loatSumPrice!=null && loatSumPrice>0){
            int lastCount=list.size();
            loatSumPrice=loatSumPrice/lastCount;
            priceMap.put("loatSumPrice",loatSumPrice*0.95);

        }else{

        }



        return priceMap;



    }
    //返回均单价表相对面积范围
    private String retrunAvgArea(Double area){
        if(area!=null){
            if(area>140){
                return "180-9999";
            }else if(area>=120){
                return "120-140";
            }else if(area>=90){
                return "90-120";
            }else if(area>=70){
                return "70-90";
            }else if(area>=1){
                return "0-70";
            }
        }
        return null;
    }

    /**
     * 获取计算rp值
     * @param params 房产信息
     * @return
     */
    private double getRpValue(Map<String, Object> params){
        double RpValue=0.0;
        /*-----------根据输入匹配数据库Rp---key----------------*/
        String houseTypeKey="";//暂无户型配置参数
        String placeTypeKey=MapUtils.getString(params,"placeType");//朝向参数
        String foolerKey=this.getFloor(MapUtils.getDouble(params,"floor"));//通过方法得到rp默认楼层配置key
        String acreageKey=this.getArea(MapUtils.getDouble(params,"acreage"));
      /*-----------取数据库rp值配置信息----------------------*/
        List<HouseRpValueDto> rps = houseMapper.selectRpValue();//获取默认配置rp值参数
        //进行参数匹配得到对应rp值
        double foolerRp=this.getRpValueByKey(foolerKey,rps);
        double acreageRp=this.getRpValueByKey(acreageKey,rps);
        double placeTypeRp=this.getRpValueByKey(placeTypeKey,rps);
        RpValue=foolerRp*acreageRp*placeTypeRp;
        if(RpValue>0)
            return RpValue;
        else
            return 1.0;
    }
    //Rp值参数匹配
    private double getRpValueByKey(String key, List<HouseRpValueDto> rps){
        for(HouseRpValueDto rp:rps){
            if(rp.getKey().equals(key)){
                return rp.getValue();
            }
        }
        return 1.0;//默认返回1
    }

    //获取楼层范围
    private String getFloor(Double f){

        if(f>15){
            return "15层以上";
        }else if(f>=9){
            return "9-15层";
        }else if(f>=7){
            return "7-8层";
        }else if(f>=3){
            return "3-6层";
        }else if(f>=1){
            return "1-2层";
        }
        return "";
    }
    //获取面积范围
    private String getArea(double a){

        if(a>146){
            return "146㎡以上";
        }else if(a>=121){
            return "121-145㎡";
        }else if(a>=81){
            return "81-120㎡";
        }else if(a>=61){
            return "61-80㎡";
        }else if(a>=1){
            return "1-60㎡";
        }
        return "";
    }
    /**
     * 获取房产详情参数集合
     * @param params 房产信息基本参数
     * @return （小区动态成交，在售，房产增值统计图表，小区成交价格统计图表）
     */
    @Override
    public Map<String, Object> getHouseDetailCountMap(Map<String, Object> params) {
        Map<String,Object> map=new HashedMap();
        //房产增值图表List
        List<Map<String,Object>> houseReaList=new ArrayList<Map<String, Object>>();
        //小区成交图表List
        List<Map<String,Object>> houseEdList=new ArrayList<Map<String, Object>>();
        //小区动态成交（小区成交数据）
        List<Map<String,Object>>  dynamicCellBarginList=new ArrayList<Map<String, Object>>();
        //小区动态在售（网络报盘）
        List<Map<String,Object>>  dynamicCellSaleList=new ArrayList<Map<String, Object>>();
        String orderNo=MapUtils.getString(params,"orderNo");
        String propertyName=MapUtils.getString(params,"propertyName");

        String label=propertyName;
        params.put("label",label);
        try {
            //房产增值图表List
            //houseReaList=houseMapper.selectHouseRealEstateAccrued(orderNo);房产增值图表
            Map<String,String> getAvgMap=new HashedMap();
            getAvgMap.put("propertyName",propertyName);
            getAvgMap.put("buildingName",MapUtils.getString(params,"buildingName"));
            String areKey=this.retrunAvgArea(MapUtils.getDouble(params,"acreage"));
            getAvgMap.put("area",areKey);
            List<TZCPropertyDto> listAvgPrice=propertyAVGService.selectTZCPropertyDtoByMonthBefore12(getAvgMap);
            TZCPropertyDto tzcPto=null;
            houseEdList=houseMapper.selectHouseEstateDeal(propertyName);
            Map<String,TZCPropertyDto> edMap=new LinkedHashMap<String, TZCPropertyDto>();
            for(int i=0;i<houseEdList.size();i++){
                Map<String,Object> mapTemp= houseEdList.get(i);
                tzcPto=new TZCPropertyDto();
                tzcPto.setEstatePrice(MapUtils.getDouble(mapTemp,"unitPrice"));
                tzcPto.setMonths(MapUtils.getString(mapTemp,"months"));
                edMap.put(MapUtils.getString(mapTemp,"months"),tzcPto);
            }
            for (TZCPropertyDto tzcpd:listAvgPrice
                 ) {
                if(edMap.get(tzcpd)==null){
                    edMap.put(tzcpd.getMonths(),tzcpd);
                }else{
                    edMap.put(tzcpd.getMonths(),tzcpd);
                }
            }
            List<TZCPropertyDto> newTZCListDto=new ArrayList<TZCPropertyDto>();
            Iterator<String> it = edMap.keySet().iterator();
            while(it.hasNext()){
                String key = it.next();
                tzcPto=new TZCPropertyDto();
                tzcPto =edMap.get(key);
                newTZCListDto.add(tzcPto);
            }
            /**------------------*/
            houseReaList=this.avgToReaListPlan(newTZCListDto,params);

            if(CollectionUtils.isNotEmpty(houseReaList)){
                map.put("houseReaList",houseReaList);
            }else{
                Map<String,Object> newMapHouseReaList=new HashedMap();
                SimpleDateFormat sdfs=new SimpleDateFormat("yy/MM");
                String nowDate=sdfs.format(new Date());
                if(MapUtils.getDouble(params,"sumPrice")>0){
                    newMapHouseReaList.put("sumPrice",MapUtils.getString(params,"sumPrice"));
                    newMapHouseReaList.put("months",nowDate);
                    houseReaList.add(newMapHouseReaList);
                    map.put("houseReaList",houseReaList);
                }else{
                    map.put("houseReaList",null);
                }
            }

        } catch (Exception e) {
            map.put("houseReaList",null);
            e.printStackTrace();
        }
        try {
            //小区成交图表List
            houseEdList=houseMapper.selectHouseEstateDeal(propertyName);
            if(CollectionUtils.isNotEmpty(houseEdList)){
                map.put("houseEdList",houseEdList);
            }else{
                map.put("houseEdList",null);
            }
        } catch (Exception e) {
            map.put("houseEdList",null);
            e.printStackTrace();
        }
        try {
            //小区动态成交（小区成交数据）
            dynamicCellBarginList=houseDetailMapper.selectDynamicCellBargin(params);
            if(CollectionUtils.isNotEmpty(dynamicCellBarginList)){
                map.put("dynamicCellBarginList",dynamicCellBarginList);
            }else{
                map.put("dynamicCellBarginList",null);
            }
        } catch (Exception e) {
            map.put("dynamicCellBarginList",null);
            e.printStackTrace();
        }
        try {
            //小区动态在售（网络报盘）
            dynamicCellSaleList=houseDetailMapper.selectDynamicCellSale(params);
            if(CollectionUtils.isNotEmpty(dynamicCellSaleList)){
                map.put("dynamicCellSaleList",dynamicCellSaleList);
            }else{
                map.put("dynamicCellSaleList",null);
            }

        } catch (Exception e) {
            map.put("dynamicCellSaleList",null);
            e.printStackTrace();
        }


        return map;
    }
    //返回计算房产月增至数据
    public List<Map<String,Object>> avgToReaListPlan(List<TZCPropertyDto> listAvgPrice,Map<String,Object> params){
        //房产增值图表List
        List<Map<String,Object>> houseReaList=new ArrayList<Map<String, Object>>();
        if(CollectionUtils.isNotEmpty(listAvgPrice)){
            for(TZCPropertyDto tpd:listAvgPrice){
                params.put("avgMouthPrice",tpd.getEstatePrice());
                params.put("avgMouth",tpd.getMonths());
                //封装参数进行计算返回结果
                Map<String,Object> avgMouthMap=this.computeAvgMouthPrice(params);
                houseReaList.add(avgMouthMap);
            }
        }
        return houseReaList;
    }

    //计算房产增值月数据类
    public Map<String, Object> computeAvgMouthPrice(Map<String, Object> params) {
        double sumPrice=0.0;//总价
        double rp=this.getRpValue(params);//rp值
        //均单价
        double avgPrice=0.0;
        Map<String,Object> avgMouthMap=new HashedMap();
        try {
            //avgPrice=this.getHousePrice(params);//通过接口获取均单价
            avgPrice=MapUtils.getDouble(params,"avgMouthPrice");//通过zL查询月单价接口返回
            Double loadPrice=avgPrice-avgPrice*0.2;
            Double rpPrice=avgPrice*0.2*rp;
            avgPrice=rpPrice+loadPrice;
            BigDecimal bg=new BigDecimal(avgPrice);
            avgPrice=bg.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
            if(Double.isNaN(avgPrice)){
                params.put("avgPrice",null);
                return params;
            }else{
                if(avgPrice>0){
                    int acreage=MapUtils.getIntValue(params,"acreage");//获取面积
                    sumPrice=avgPrice * acreage;//总价
                    BigDecimal bgs=new BigDecimal(sumPrice);
                    avgMouthMap.put("sumPrice",bgs.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());//现总价
                    avgMouthMap.put("months",MapUtils.getString(params,"avgMouth"));
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }




        return avgMouthMap;
    }
    /**
     * 获取房产更新后参数信息（买卖税费，学位占用，产权情况）
     * @param param
     * @return
     */
    @Override
    public Map<String, Object> selectHouseUpdateBase(Map<String, Object> param) {

        return houseMapper.selectHouseUpdateBase(param);
    }

    /**
     * 小区动态成交（小区成交数据根据参数查看更多）
     * @return
     */
    @Override
    public List<Map<String, Object>> selectDynamicCellBarginMoreList(Map<String, Object> param) {
        return houseDetailMapper.selectDynamicCellBarginMoreList(param);
    }
    /**
     * 小区动态在售（网络报盘根据参数查看更多）
     * @return
     */
    @Override
    public List<Map<String, Object>> selectDynamicCellSaleMoreList(Map<String, Object> param) {
        return houseDetailMapper.selectDynamicCellSaleMoreList(param);
    }

    /**
     * 获取房产详情运营后台调用
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> selectHouseDetailById(String id) {
        return houseMapper.selectHouseDetailById(id);
    }
    /**
     * 首页获取房产总信息
     * @param params
     * @return
     */
    @Override
    public Map<String, Object> selectHouseAssetByIndex(Map<String, Object> params) {
        List<Map<String, Object>> list= null;
        int sumPrice=0;
        int appreciation=0;
       /* int loanBalance=0;*/
        int hasHouse=0;
        try {
            list = houseMapper.selectHouseAssetByIndex(params);
            hasHouse=houseMapper.selectHasHouseList(params);
        } catch (Exception e) {
            e.printStackTrace();
        }


        for(int i=0;i<list.size();i++){
            Map<String,Object> mapTemp=list.get(i);

            sumPrice+=(int)(MapUtils.getDouble(mapTemp,"sumPrice")/10000);
            appreciation+=(int)(MapUtils.getDouble(mapTemp,"appreciation")/10000);

            /*loanBalance+=Math.floor(MapUtils.getDouble(mapTemp,"loanBalance")/10000);*/
        }

        Map<String,Object> map =new HashMap<String,Object>();
        map.put("sumPrice",sumPrice);
        map.put("appreciation",appreciation);
        map.put("hasHouse",hasHouse);
        map.put("houseList",list);

        return map;
    }

    /**
     * 获取上月单价得到相比上月增值
     * @param params
     * @return
     */
    @Override
    public Double complateAvgLastMouth(Map<String, Object> params) {
        Map<String,String> getAvgMap=new HashedMap();
        getAvgMap.put("propertyName",MapUtils.getString(params,"propertyName"));
        getAvgMap.put("buildingName",MapUtils.getString(params,"buildingName"));
        getAvgMap.put("houseType",MapUtils.getString(params,"houseType"));
        TZCPropertyDto tzcPropertyDto=propertyAVGService.selectAvgByLastMouth(getAvgMap);
        double appreciationOf=0.0;
        if(tzcPropertyDto!=null){

            params.put("avgMouthPrice",tzcPropertyDto.getEstatePrice());
            params.put("avgMouth",tzcPropertyDto.getMonths());
            Map<String,Object> avgMouthMap=this.computeAvgMouthPrice(params);
            double sumPrice=MapUtils.getDouble(params,"sumPrice");
            double lastSumPrice=MapUtils.getDouble(avgMouthMap,"sumPrice");
            appreciationOf=sumPrice-lastSumPrice;
//            appreciationOf=appreciationOf/sumPrice;
        }

        return appreciationOf;
    }


}
